Designing a true MVC framework, how feasible is this?

As oddz mentioned, the “real” MVC, as it was meant to work in desktop applications, isn’t terribly applicable to server-side web applications.

In traditional desktop MVC, every window, every input box, every button is a separate view, and each of those views has its own controller. The job of each of those controllers is to interpret mouse/keyboard/whatever inputs from the user. So, for example, the input box’s controller might interpret a click as a command for the view to focus that element. Or the button’s controller might interpret a click as a command for the model to save data. In web MVC, however, the controller’s job is vastly different. There won’t be any mouse or keyboard inputs. There’s just the HTTP request. And the controller’s job is to convert that request into an HTTP response.

Fowler, on the other hand, seems less interested in how MVC has been specifically implemented in desktop software and more interested in the principles and values it provides.

“As I think about MVC I see two principal separations: separating the presentation from the model and separating the controller from the view.”

When he applied these principles to the web, he came up with this:

He says, “The basic responsibilities of a Page Controller are:
" * Decode the URL and extract any form data to figure out all the data for the action.
" * Create and invoke any model objects to process the data. All relevant data from the HTML request should be passed to the model so that the model objects don’t need any connection to the HTML request.
" * Determine which view should display the result page and forward the model information to it.”

Interestingly, this is how the modern frameworks already work.

The diagram suggests just one possible difference: whether the view should access the model directly. But Fowler does this differently than how you might expect.



Notice that the controller queries the data, and the controller makes the result of that query available to the view. This behavior matches one of the controller responsibilities Fowler listed: “Determine which view should display the result page and forward the model information to it.” Interestingly, this too is how the modern frameworks already work. Fowler even acknowledges that the view acts like a template, which is why he calls it a Template View.

You want to implement Fowler’s idea of MVC… but it seems to me that his idea of MVC and how the modern frameworks work are already one and the same.